package code.rocky.sync;

/**
 * 局部变量操作没有安全问题
 */
public class SyncTest {

    public static void main(String[] args) {
        SyncTest syncTest = new SyncTest();
        new Thread(()->{
            syncTest.printMessage(1);
        },"t1") .start();

        new Thread(()->{
            syncTest.printMessage(2);
        },"t2") .start();

        System.out.println("=======end=======");
    }

    private void printMessage(int code) {
        int num = 0;
        if (code == 1) {
            num = 1;
        }
        else {
            num = 2;
        }
        System.out.println(Thread.currentThread().getName() + " 线程 print number: " + num);
    }
}
